package com.ysm.smfu.holder;

import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Adapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ysm.smfu.R;
import com.ysm.smfu.bean.BankBean;
import com.ysm.smfu.fragment.MyBankFragment;
import com.ysm.smfu.utils.UIUtils;

import java.util.List;

import butterknife.OnClick;

/**
 * Created by Administrator on 2016/9/27.
 */
public class BankHolder extends BaseHolder<BankBean> {

    private final Fragment fragment;
    BankBean data;
    private final Adapter adapter;
    private ImageView holderBankPic;
    private TextView holderBankName;
    private TextView holderBankType;
    private TextView holderBankNumber;
    private ImageView holderBankDel;
    private ImageView holderBankDel1;

    public BankHolder(Adapter adapter, Fragment fragment) {
        this.adapter = adapter;
        this.fragment = fragment;
    }

    @Override
    protected View initView() {
        View view = UIUtils.inflate(R.layout.holder_bank);
        holderBankPic = (ImageView) view.findViewById(R.id.holder_bank_pic);
        holderBankName = (TextView) view.findViewById(R.id.holder_bank_name);
        holderBankType = (TextView) view.findViewById(R.id.holder_bank_type);
        holderBankNumber = (TextView) view.findViewById(R.id.holder_bank_number);
        holderBankDel1 = (ImageView) view.findViewById(R.id.holder_bank_del);
        return view;
    }

    @Override
    protected void refreshView(BankBean data) {
        this.data = data;
        Glide.with(fragment).load(data.url).into(holderBankPic);
        holderBankName.setText(data.name);
        holderBankType.setText(data.type);
        holderBankNumber.setText(String.valueOf(data.number));
    }

    @OnClick(R.id.holder_bank_type)
    public void onClick() {
        if (adapter instanceof MyBankFragment.MyAdapter) {
            List<BankBean> datas = ((MyBankFragment.MyAdapter) adapter).getDatas();
            datas.remove(data);
            ((MyBankFragment.MyAdapter) adapter).notifyDataSetChanged();
        }
    }
}
